/*
* math and geometry functions
*/

#pragma once
#include <iostream>
#include <vector>

namespace vortex
{
    struct Rect
    {
        uint32_t x;
        uint32_t y;
        uint32_t width;
        uint32_t height;

        friend std::ostream& operator<<(std::ostream& os, const Rect& rect);
    };

    template<typename T>
    struct DetBox
    {
        T left;
        T right;
        T top;
        T bottom;
        float score;
        uint32_t class_id;

        T Area() const { return (right - left) * (bottom - top); }
    };

    typedef DetBox<float> DetBoxF;

    // box overlap
    float BoxIoU(const DetBoxF& box1, const DetBoxF& box2);
    bool DetBoxLess(const DetBoxF& box1, const DetBoxF& box2);

    // math functions
    template<typename T>
    std::pair<int32_t, T> Argmax(const std::vector<T>& array)
    {
        if (array.size() == 0) 
            return std::make_pair<int32_t, T>(-1, 0);
        
        int32_t max_index = 0;
        T max_value = array[0];
        for (size_t i = 0; i < array.size(); ++i)
        {
            if (array[i] > max_value)
            {
                max_value = array[i];
                max_index = i;
            }
        }
        return std::make_pair(max_index, max_value);
    }



}
